<?php
	class xl_tim_dich_vu_dia_diem extends database
	{
		// tìm nhóm
		function danhSachNhom($idwhat)
		{
			
			$this->setQuerry("select * from nhomdiadiem where manhomdiadiem like=".$idwhat);
			$result = $this->loadAllRow();
			return $result;
		}
		//end
		
		// tìm quận
		function timKiemTinhThanh($idwhere)
		{
			
			$this->setQuerry("select * from tinhthanh,quanhuyen where tinhthanh.matinhthanh=quanhuyen.matinhthanh and tinhthanh.matinhthanh=".$idwhere);
			$result = $this->loadAllRow();
			return $result;
		}
		// end
		
		// 1. what = nhóm địa điểm + where = quận tỉnh
		function tongTimKiemNhomWhere($idquan,$idtinh,$manhom)
		{
			$sql;
			$sql="select * from nhomdiadiem,diadiem, tinhthanh, quanhuyen where quanhuyen.maquanhuyen=diadiem.maquanhuyen and diadiem.matinhthanh=tinhthanh.matinhthanh and nhomdiadiem.manhomdiadiem=".$manhom." and tinhthanh.matinhthanh=quanhuyen.matinhthanh and nhomdiadiem.manhomdiadiem=diadiem.manhomdiadiem ";
			if($idquan!=0)
				 $sql=$sql.""."and quanhuyen.maquanhuyen=".$idquan." ";
			if($idtinh!=0)
				$sql=$sql.""."and tinhthanh.matinhthanh=".$idtinh." ";
			$this->setQuerry($sql);
			$result = $this->loadAllRow();
			return $result;
		}
		
		function danhSachTimKiemNhomWhere_first($idquan,$idtinh,$manhom)
		{
			$result;
			$sql;
			$sql="select * from nhomdiadiem,diadiem, tinhthanh, quanhuyen where quanhuyen.maquanhuyen=diadiem.maquanhuyen and diadiem.matinhthanh=tinhthanh.matinhthanh and nhomdiadiem.manhomdiadiem=diadiem.manhomdiadiem and tinhthanh.matinhthanh=quanhuyen.matinhthanh ";
			if($idquan!=0)
				 $sql=$sql.""."and quanhuyen.maquanhuyen=".$idquan." ";
			if($idtinh!=0)
				$sql=$sql.""."and tinhthanh.matinhthanh=".$idtinh." ";
			$sql=$sql.""."and nhomdiadiem.manhomdiadiem=".$manhom." order by diadiem.madiadiem ASC limit 0,10";
			$this->setQuerry($sql);
			$result = $this->loadAllRow();
			return $result;
		}
		
		function danhSachTimKiemNhomWhere_ViewMore($idquan,$idtinh,$manhom,$madiadiem)
		{
			$result;
			$sql="select * from nhomdiadiem,diadiem, tinhthanh, quanhuyen where quanhuyen.maquanhuyen=diadiem.maquanhuyen and diadiem.matinhthanh=tinhthanh.matinhthanh and nhomdiadiem.manhomdiadiem=diadiem.manhomdiadiem and  tinhthanh.matinhthanh=quanhuyen.matinhthanh ";
			if($idquan!=0)
				 $sql=$sql.""."and quanhuyen.maquanhuyen=".$idquan." ";
			if($idtinh!=0)
				$sql=$sql.""."and tinhthanh.matinhthanh=".$idtinh." ";
			$sql=$sql.""."and nhomdiadiem.manhomdiadiem=".$manhom." and diadiem.madiadiem > ".$madiadiem." order by diadiem.madiadiem ASC limit 0,10";
			$this->setQuerry($sql);
			$result = $this->loadAllRow();
			return $result;
		}
		// end 1
		
		// 2. what = tên địa điểm + where = null
		function tongTimKiemWhat($what)
		{
				$sql="select * from nhomdiadiem,diadiem, tinhthanh, quanhuyen where quanhuyen.maquanhuyen=diadiem.maquanhuyen and diadiem.matinhthanh=tinhthanh.matinhthanh and nhomdiadiem.manhomdiadiem=diadiem.manhomdiadiem and tinhthanh.matinhthanh=quanhuyen.matinhthanh and diadiem.tendiadiem like N'%".$what."%' order by diadiem.madiadiem ASC";
			$this->setQuerry($sql);
			$result = $this->loadAllRow();
			return count($result);
		}
		
		function danhSachTimKiemWhat_first($what)
		{
			$result;
			$sql="select * from nhomdiadiem,diadiem, tinhthanh, quanhuyen where quanhuyen.maquanhuyen=diadiem.maquanhuyen and diadiem.matinhthanh=tinhthanh.matinhthanh and nhomdiadiem.manhomdiadiem=diadiem.manhomdiadiem and tinhthanh.matinhthanh=quanhuyen.matinhthanh and diadiem.tendiadiem like N'%".$what."%' order by diadiem.madiadiem ASC limit 0,10";
			$this->setQuerry($sql);
			$result = $this->loadAllRow();
			return $result;
		}
		
		function danhSachTimKiemWhat_ViewMore($what,$madiadiem)
		{
			$result;
			$sql="select * from nhomdiadiem,diadiem, tinhthanh, quanhuyen where quanhuyen.maquanhuyen=diadiem.maquanhuyen and diadiem.matinhthanh=tinhthanh.matinhthanh and nhomdiadiem.manhomdiadiem=diadiem.manhomdiadiem and tinhthanh.matinhthanh=quanhuyen.matinhthanh and diadiem.tendiadiem like N'%".$what."%' and diadiem.madiadiem > ".$madiadiem." order by diadiem.madiadiem ASC limit 0,10";
			$this->setQuerry($sql);
			$result = $this->loadAllRow();
			return $result;
		}
		
		// end 2
		
		
		// 3. what = null + where = quận tỉnh
		function tongTimKiemWhere($idquan,$idtinh)
		{
			$sql;
			if($idquan!="")
				$sql="select * from nhomdiadiem,diadiem, tinhthanh, quanhuyen where quanhuyen.maquanhuyen=diadiem.maquanhuyen and diadiem.matinhthanh=tinhthanh.matinhthanh and tinhthanh.matinhthanh=quanhuyen.matinhthanh and nhomdiadiem.manhomdiadiem=diadiem.manhomdiadiem and quanhuyen.tenquanhuyen=".$idquan." ";
			if($idtinh!="")
				$sql+="and tinhthanh.tentinhthanh=".$idtinh." ";
			$sql+="order by diadiem.madiadiem ASC limit 0,10";
			$this->setQuerry($sql);
			$result = $this->loadAllRow();
			return count($result);
		}
		
		function danhSachTimKiemWhere_first($idquan,$idtinh)
		{
			$sql;
			if($idquan!="")
				$sql="select * from nhomdiadiem,diadiem, tinhthanh, quanhuyen where 			quanhuyen.maquanhuyen=diadiem.maquanhuyen and diadiem.matinhthanh=tinhthanh.matinhthanh and nhomdiadiem.manhomdiadiem=diadiem.manhomdiadiem and tinhthanh.matinhthanh=quanhuyen.matinhthanh and quanhuyen.tenquanhuyen=".$idquan." ";
			if($idtinh!="")
				$sql+="and tinhthanh.tentinhthanh=".$idtinh." ";
			$sql+="order by diadiem.madiadiem ASC limit 0,10";
			$this->setQuerry($sql);
			$result = $this->loadAllRow();
			return $result;
		}
		
		function danhSachTimKiemWhere_ViewMore($idquan,$idtinh,$madiadiem)
		{
			$result;
			$sql;
			if($idquan!="")
				$sql="select * from nhomdiadiem,diadiem, tinhthanh, quanhuyen where quanhuyen.maquanhuyen=diadiem.maquanhuyen and diadiem.matinhthanh=tinhthanh.matinhthanh and nhomdiadiem.manhomdiadiem=diadiem.manhomdiadiem and tinhthanh.matinhthanh=quanhuyen.matinhthanh and quanhuyen.tenquanhuyen=".$idquan." ";
			if($idtinh!="")
				$sql+="and tinhthanh.tentinhthanh=".$idtinh." ";
			$sql+="and diadiem.madiadiem > ".$madiadiem." order by diadiem.madiadiem ASC limit 0,10";
			$this->setQuerry($sql);
			$result = $this->loadAllRow();
			return $result;
		}
		
		// end 3
		
		// 4. what = tên địa điểm + where = quận tỉnh
		function tongTimKiem_What_Quan_Huyen($what,$idquan,$idtinh)
		{
			$sql;
			$sql="select * from nhomdiadiem,diadiem, tinhthanh, quanhuyen where quanhuyen.maquanhuyen=diadiem.maquanhuyen and diadiem.matinhthanh=tinhthanh.matinhthanh and tinhthanh.matinhthanh=quanhuyen.matinhthanh and nhomdiadiem.manhomdiadiem=diadiem.manhomdiadiem and diadiem.tendiadiem like '%".$what."%' "; 
			if($idquan!=0)
				 $sql=$sql.""."and quanhuyen.maquanhuyen=".$idquan." ";
			if($idtinh!=0)
				$sql=$sql.""."and tinhthanh.matinhthanh=".$idtinh;
			$this->setQuerry($sql);
			$result = $this->loadAllRow();
			return count($result);
		}
		
		function danhSachTimKiem_What_Quan_Huyen_first($what,$idquan,$idtinh)
		{
			$sql;
			
			$sql="select * from nhomdiadiem,diadiem, tinhthanh, quanhuyen where quanhuyen.maquanhuyen=diadiem.maquanhuyen and diadiem.matinhthanh=tinhthanh.matinhthanh and tinhthanh.matinhthanh=quanhuyen.matinhthanh and nhomdiadiem.manhomdiadiem=diadiem.manhomdiadiem and diadiem.tendiadiem like '%".$what."%' "; 
			if($idquan!=0)
				 $sql=$sql.""."and quanhuyen.maquanhuyen=".$idquan." ";
			if($idtinh!=0)
				$sql=$sql.""."and tinhthanh.matinhthanh=".$idtinh." ";
			$sql=$sql."order by diadiem.madiadiem ASC limit 0,10";
			$this->setQuerry($sql);
			$result = $this->loadAllRow();
			return $result;
		}
		
		function danhSachTimKiem_What_Quan_Huyen_ViewMore($what,$idquan,$idtinh,$madiadiem)
		{
			$result;
		
			$sql="select * from nhomdiadiem,diadiem, tinhthanh, quanhuyen where quanhuyen.maquanhuyen=diadiem.maquanhuyen and diadiem.matinhthanh=tinhthanh.matinhthanh and tinhthanh.matinhthanh=quanhuyen.matinhthanh and nhomdiadiem.manhomdiadiem=diadiem.manhomdiadiem and diadiem.tendiadiem like '%".$what."%' "; 
			if($idquan!=0)
				 $sql=$sql.""."and quanhuyen.maquanhuyen=".$idquan." ";
			if($idtinh!=0)
				$sql=$sql.""."and tinhthanh.matinhthanh=".$idtinh." ";
			$sql=$sql."and diadiem.madiadiem > ".$madiadiem." order by diadiem.madiadiem ASC limit 0,10";
			$this->setQuerry($sql);
			$result = $this->loadAllRow();
			return $result;
		}
		// == 5. what= nhóm địa điểm + where = đường
		function tongTimKiemNhomDuong($duong,$manhom)
		{
			$sql;
			$sql="select * from nhomdiadiem,diadiem, tinhthanh, quanhuyen where quanhuyen.maquanhuyen=diadiem.maquanhuyen and diadiem.matinhthanh=tinhthanh.matinhthanh and tinhthanh.matinhthanh=quanhuyen.matinhthanh and nhomdiadiem.manhomdiadiem=".$manhom." and diadiem.diachi like '%".$duong."%' and nhomdiadiem.manhomdiadiem=diadiem.manhomdiadiem ";
			
			$this->setQuerry($sql);
			$result = $this->loadAllRow();
			return $result;
		}
		
		function danhSachTimKiemNhomDuong_first($duong,$manhom)
		{
			$result;
			$sql;
			$sql="select * from nhomdiadiem,diadiem, tinhthanh, quanhuyen where quanhuyen.maquanhuyen=diadiem.maquanhuyen and diadiem.matinhthanh=tinhthanh.matinhthanh and tinhthanh.matinhthanh=quanhuyen.matinhthanh and diadiem.diachi like '%".$duong."%' and nhomdiadiem.manhomdiadiem=diadiem.manhomdiadiem ";
			$sql=$sql.""."and nhomdiadiem.manhomdiadiem=".$manhom." order by diadiem.madiadiem ASC limit 0,10";
			$this->setQuerry($sql);
			$result = $this->loadAllRow();
			return $result;
		}
		
		function danhSachTimKiemNhomDuong_ViewMore($duong,$manhom,$madiadiem)
		{
			$result;
			$sql;
			$sql="select * from nhomdiadiem,diadiem, tinhthanh, quanhuyen where quanhuyen.maquanhuyen=diadiem.maquanhuyen and diadiem.matinhthanh=tinhthanh.matinhthanh and tinhthanh.matinhthanh=quanhuyen.matinhthanh and diadiem.diachi like '%".$duong."%' and nhomdiadiem.manhomdiadiem=diadiem.manhomdiadiem ";
			
			$sql=$sql.""."and nhomdiadiem.manhomdiadiem=".$manhom." and diadiem.madiadiem > ".$madiadiem." order by diadiem.madiadiem ASC limit 0,10";
			$this->setQuerry($sql);
			$result = $this->loadAllRow();
			return $result;
		}
		// end 5*
		
		// == 6. what= tên địa điểm + where = đường 
		function tongTimKiemWhatDuong($duong,$what)
		{
			$sql;
			$sql="select * from nhomdiadiem,diadiem, tinhthanh, quanhuyen where quanhuyen.maquanhuyen=diadiem.maquanhuyen and diadiem.matinhthanh=tinhthanh.matinhthanh and tinhthanh.matinhthanh=quanhuyen.matinhthanh and diadiem.tendiadiem like '%".$what."%' and diadiem.diachi like '%".$duong."%' and nhomdiadiem.manhomdiadiem=diadiem.manhomdiadiem ";
			$this->setQuerry($sql);
			$result = $this->loadAllRow();
			return count($result);
		}
		
		function danhSachTimKiemWhatDuong_first($duong,$what)
		{
			$result;
			$sql;
			$sql="select * from nhomdiadiem,diadiem, tinhthanh, quanhuyen where quanhuyen.maquanhuyen=diadiem.maquanhuyen and diadiem.matinhthanh=tinhthanh.matinhthanh and tinhthanh.matinhthanh=quanhuyen.matinhthanh and diadiem.diachi like '%".$duong."%' and nhomdiadiem.manhomdiadiem=diadiem.manhomdiadiem ";
			$sql=$sql.""."and diadiem.tendiadiem like '%".$what."%' order by diadiem.madiadiem ASC limit 0,10";
			$this->setQuerry($sql);
			$result = $this->loadAllRow();
			return $result;
		}
		
		function danhSachTimKiemWhatDuong_ViewMore($duong,$what,$madiadiem)
		{
			$result;
			$sql;
			$sql="select * from nhomdiadiem,diadiem, tinhthanh, quanhuyen where quanhuyen.maquanhuyen=diadiem.maquanhuyen and diadiem.matinhthanh=tinhthanh.matinhthanh and tinhthanh.matinhthanh=quanhuyen.matinhthanh and diadiem.diachi like '%".$duong."%' and nhomdiadiem.manhomdiadiem=diadiem.manhomdiadiem ";
			$sql=$sql.""."and diadiem.tendiadiem like '%".$what."%' and diadiem.madiadiem > ".$madiadiem." order by diadiem.madiadiem ASC limit 0,10";
			$this->setQuerry($sql);
			$result = $this->loadAllRow();
			return $result;
		}
		//end 6
		
		// == 7. what = null + where = đường
		function tongTimKiemDuong($duong)
		{
			$sql;
			$sql="select * from nhomdiadiem,diadiem, tinhthanh, quanhuyen where quanhuyen.maquanhuyen=diadiem.maquanhuyen and diadiem.matinhthanh=tinhthanh.matinhthanh and tinhthanh.matinhthanh=quanhuyen.matinhthanh and diadiem.diachi like '%".$duong."%' and nhomdiadiem.manhomdiadiem=diadiem.manhomdiadiem ";
			$this->setQuerry($sql);
			$result = $this->loadAllRow();
			return count($result);
		}
		
		function danhSachTimKiemDuong_first($duong)
		{
			$result;
			$sql;
			$sql="select * from nhomdiadiem,diadiem, tinhthanh, quanhuyen where quanhuyen.maquanhuyen=diadiem.maquanhuyen and diadiem.matinhthanh=tinhthanh.matinhthanh and tinhthanh.matinhthanh=quanhuyen.matinhthanh and diadiem.diachi like '%".$duong."%' and nhomdiadiem.manhomdiadiem=diadiem.manhomdiadiem order by diadiem.madiadiem ASC limit 0,10";
			$this->setQuerry($sql);
			$result = $this->loadAllRow();
			return $result;
		}
		
		function danhSachTimKiemDuong_ViewMore($duong,$madiadiem)
		{
			$result;
			$sql;
		$sql="select * from nhomdiadiem,diadiem, tinhthanh, quanhuyen where quanhuyen.maquanhuyen=diadiem.maquanhuyen and diadiem.matinhthanh=tinhthanh.matinhthanh and tinhthanh.matinhthanh=quanhuyen.matinhthanh and diadiem.diachi like '%".$duong."%' and nhomdiadiem.manhomdiadiem=diadiem.manhomdiadiem and diadiem.madiadiem > ".$madiadiem." order by diadiem.madiadiem ASC limit 0,10";
			$this->setQuerry($sql);
			$result = $this->loadAllRow();
			return $result;
		}
		//end 7
		
		// ==8. what=null + where = quận tỉnh
		function tongTimKiemQuanTinh($idquan,$idtinh)
		{
			$sql;
			$sql="select * from nhomdiadiem,diadiem, tinhthanh, quanhuyen where quanhuyen.maquanhuyen=diadiem.maquanhuyen and diadiem.matinhthanh=tinhthanh.matinhthanh and nhomdiadiem.manhomdiadiem=diadiem.manhomdiadiem and quanhuyen.matinhthanh=tinhthanh.matinhthanh "; 
			if($idquan!=0)
				 $sql=$sql.""."and quanhuyen.maquanhuyen=".$idquan." ";
			if($idtinh!=0)
				$sql=$sql.""."and tinhthanh.matinhthanh=".$idtinh;
			$this->setQuerry($sql);
			$result = $this->loadAllRow();
			return count($result);
		}
		
		function danhSachTimKiemQuanTinh_first($idquan,$idtinh)
		{
			$sql;
			
			$sql="select * from nhomdiadiem,diadiem, tinhthanh, quanhuyen where quanhuyen.maquanhuyen=diadiem.maquanhuyen and diadiem.matinhthanh=tinhthanh.matinhthanh and nhomdiadiem.manhomdiadiem=diadiem.manhomdiadiem and quanhuyen.matinhthanh=tinhthanh.matinhthanh "; 
			if($idquan!=0)
				 $sql=$sql.""."and quanhuyen.maquanhuyen=".$idquan." ";
			if($idtinh!=0)
				$sql=$sql.""."and tinhthanh.matinhthanh=".$idtinh." order by diadiem.madiadiem ASC limit 0,10";
			$this->setQuerry($sql);
			$result = $this->loadAllRow();
			return $result;
		}
		
		function danhSachTimKiemQuanTinh_Viewmore($idquan,$idtinh,$madiadiem)
		{
			$result;
		
			$sql="select * from nhomdiadiem,diadiem, tinhthanh, quanhuyen where quanhuyen.maquanhuyen=diadiem.maquanhuyen and diadiem.matinhthanh=tinhthanh.matinhthanh and nhomdiadiem.manhomdiadiem=diadiem.manhomdiadiem and quanhuyen.matinhthanh=tinhthanh.matinhthanh "; 
			if($idquan!=0)
				 $sql=$sql.""."and quanhuyen.maquanhuyen=".$idquan." ";
			if($idtinh!=0)
				$sql=$sql.""."and tinhthanh.matinhthanh=".$idtinh;
			$sql=$sql." and diadiem.madiadiem > ".$madiadiem." order by diadiem.madiadiem ASC limit 0,10";
			$this->setQuerry($sql);
			$result = $this->loadAllRow();
			return $result;
		}
		// end 8
	}
